package com.atguigu.Flink.sql.tableAPI;

import com.atguigu.Flink.POJO.Event;
import com.atguigu.Flink.function.ClickSource;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class Flink02_SqlHelloWorld {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<Event> ds = env.addSource(new ClickSource());
        StreamTableEnvironment streamTableEnvironment = StreamTableEnvironment.create(env);

        //在执行环境中注册表
        streamTableEnvironment.createTemporaryView("t",ds);

        //编写sql
        String sql = "select user,url,ts from t where user = 'otto'";
        //执行sql
        streamTableEnvironment.sqlQuery(sql).execute().print();

        try {
            env.execute();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
